from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional, List

class DirectoryBase(BaseModel):
    """目录基础模型"""
    name: str = Field(..., description="目录名称")
    parent_id: int = Field(0, description="父目录ID，0表示根目录")

class DirectoryCreate(DirectoryBase):
    """目录创建模型"""
    pass

class DirectoryUpdate(BaseModel):
    """目录更新模型"""
    name: Optional[str] = Field(None, description="更新的目录名称")
    parent_id: Optional[int] = Field(None, description="更新的父目录ID")

class DirectoryResponse(DirectoryBase):
    """目录响应模型"""
    id: int = Field(..., description="目录ID")
    user_id: int = Field(..., description="所属用户ID")
    path: Optional[str] = Field(None, description="目录完整路径")
    create_time: datetime = Field(..., description="创建时间")
    update_time: datetime = Field(..., description="更新时间")
    is_deleted: bool = Field(False, description="是否删除")
    
    class Config:
        """Pydantic配置"""
        from_attributes = True

class DirectoryTreeNode(BaseModel):
    """目录树节点模型，用于前端展示目录树结构"""
    id: int = Field(..., description="目录ID")
    name: str = Field(..., description="目录名称")
    path: Optional[str] = Field(None, description="目录完整路径")
    parent_id: Optional[int] = Field(None, description="父目录ID")
    children: List["DirectoryTreeNode"] = Field([], description="子目录")
    file_count: int = Field(0, description="目录下的文件数量")
    
    class Config:
        """Pydantic配置"""
        from_attributes = True

# 解决循环引用问题
DirectoryTreeNode.update_forward_refs()

class DirectoryMoveRequest(BaseModel):
    """目录移动请求"""
    directory_ids: List[int] = Field(..., description="要移动的目录ID列表")
    target_directory_id: Optional[int] = Field(None, description="目标目录ID，为null表示移动到根目录")

class BatchDeleteRequest(BaseModel):
    """批量删除文件和目录请求"""
    directory_ids: Optional[List[int]] = Field([], description="要删除的目录ID列表")
    file_ids: Optional[List[int]] = Field([], description="要删除的文件ID列表")
    permanent: bool = Field(False, description="是否永久删除，True表示从存储中彻底移除，False表示标记为已删除")
    recursive: bool = Field(True, description="删除目录时是否递归删除子目录和文件")
    
    class Config:
        schema_extra = {
            "example": {
                "directory_ids": [1, 2, 3],
                "file_ids": [4, 5, 6],
                "permanent": False,
                "recursive": True
            }
        } 